{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑轮播图</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_title" lay-verify="required" placeholder="标题"  value="{$banner.banner_title}" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">图片：</label>
                            <input type="hidden" name="banner_img" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$banner.banner_img}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">适用范围：</label>
                            <div class="layui-input-block">
                                <select name="banner_cate" lay-filter="role">
                                    <option value="1" {$banner.banner_cate==1?'selected':''}>内链</option>
                                    <option value="2" {$banner.banner_cate==2?'selected':''}>外链</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group {$banner.banner_cate == 1?'':'hidden'}" id="banner_type">
                            <label class="layui-form-label">内链类型：</label>
                            <div class="layui-input-block">
                                <select name="banner_type" lay-filter="role1">
                                    <option value="1" {$banner.banner_type==1?'selected':''}>社团详情</option>
                                    <option value="2" {$banner.banner_type==2?'selected':''}>资讯详情</option>
                                    <option value="3" {$banner.banner_type==3?'selected':''}>军婚军恋</option>
                                    <option value="4" {$banner.banner_type==4?'selected':''}>短视频</option>
                                    <option value="5" {$banner.banner_type==5?'selected':''}>悬赏问答</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_type == 1?'':'hidden'}" id="assn_id">
                            <label class="layui-form-label">选择社团：</label>
                            <div class="layui-input-block">
                                <select name="assn_id"  xm-select="select1" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="assn" item="v"}
                                    <option value="{$v.assn_id}" {$v.assn_id==$banner.banner_type_id?'selected':''}>{$v.assn_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_type == 2?'':'hidden'}" id="information_id">
                            <label class="layui-form-label">选择资讯：</label>
                            <div class="layui-input-block">
                                <select name="information_id"  xm-select="select2" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="informatioin" item="v1"}
                                    <option value="{$v1.information_id}" {$v1.information_id==$banner.banner_type_id?'selected':''}>{$v1.information_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>



                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_type == 3?'':'hidden'}" id="post_id">
                            <label class="layui-form-label">选择军婚军恋：</label>
                            <div class="layui-input-block">
                                <select name="post_id"  xm-select="select3" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="love" item="v2"}
                                    <option value="{$v2.post_id}" {$v2.post_id==$banner.banner_type_id?'selected':''}>{$v2.post_content}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>



                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_type == 4?'':'hidden'}" id="video_id">
                            <label class="layui-form-label">选择短视频：</label>
                            <div class="layui-input-block">
                                <select name="video_id"  xm-select="select4" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="video" item="v3"}
                                    <option value="{$v3.video_id}" {$v3.video_id==$banner.banner_type_id?'selected':''}>{$v3.video_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>



                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_type == 5?'':'hidden'}" id="answer_id">
                            <label class="layui-form-label">选择悬赏问答：</label>
                            <div class="layui-input-block">
                                <select name="answer_id"  xm-select="select5" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="answer" item="v4"}
                                    <option value="{$v4.answer_id}" {$v4.answer_id==$banner.banner_type_id?'selected':''}>{$v4.answer_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>



                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 {$banner.banner_cate == 2?'':'hidden'}" id="banner_link">
                            <label class="layui-form-label">外链地址：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_link" placeholder="外链地址" value="{$banner.banner_link}" class="layui-input ">
                            </div>
                        </div>




                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group" style="display: none" id="banner_type">-->
                            <!--<label class="layui-form-label">内链类型：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="banner_type" lay-filter="role1">-->
                                    <!--<option value="1" selected>社团详情</option>-->
                                    <!--<option value="2" >资讯详情</option>-->
                                    <!--<option value="3" >军婚军恋</option>-->
                                    <!--<option value="4" >短视频</option>-->
                                    <!--<option value="5" >悬赏问答</option>-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="assn_id">-->
                            <!--<label class="layui-form-label">选择社团：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="assn_id"  xm-select="select1" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">-->
                                    <!--<option value="" >请选择</option>-->
                                    <!--{foreach name="assn" item="v"}-->
                                    <!--<option value="{$v.assn_id}" >{$v.assn_name}</option>-->
                                    <!--{/foreach}-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="information_id">-->
                            <!--<label class="layui-form-label">选择资讯：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="information_id"  xm-select="select2" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">-->
                                    <!--<option value="" >请选择</option>-->
                                    <!--{foreach name="informatioin" item="v1"}-->
                                    <!--<option value="{$v1.information_id}" >{$v1.information_title}</option>-->
                                    <!--{/foreach}-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="post_id">-->
                            <!--<label class="layui-form-label">选择军婚军恋：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="post_id"  xm-select="select3" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">-->
                                    <!--<option value="" >请选择</option>-->
                                    <!--{foreach name="love" item="v2"}-->
                                    <!--<option value="{$v2.post_id}" >{$v2.post_content}</option>-->
                                    <!--{/foreach}-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="video_id">-->
                            <!--<label class="layui-form-label">选择短视频：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="video_id"  xm-select="select4" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">-->
                                    <!--<option value="" >请选择</option>-->
                                    <!--{foreach name="video" item="v3"}-->
                                    <!--<option value="{$v3.video_id}" >{$v3.video_title}</option>-->
                                    <!--{/foreach}-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="answer_id">-->
                            <!--<label class="layui-form-label">选择悬赏问答：</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<select name="answer_id"  xm-select="select5" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">-->
                                    <!--<option value="" >请选择</option>-->
                                    <!--{foreach name="answer" item="v4"}-->
                                    <!--<option value="{$v4.answer_id}" >{$v4.answer_title}</option>-->
                                    <!--{/foreach}-->
                                <!--</select>-->
                            <!--</div>-->
                        <!--</div>-->

                        <!--<div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display:none" id="banner_link">-->
                        <!--<label class="layui-form-label">外链地址：</label>-->
                        <!--<div class="layui-input-block">-->
                            <!--<input type="text" name="banner_link" placeholder="外链地址" class="layui-input" value="{$banner.banner_link}">-->
                        <!--</div>-->
                        <!--</div>-->

                        <input type="hidden" value="{$banner_id}" name="banner_id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
//    var editor = wk.wang({elem:'#LAY_editor'});
    var banner_type = 1;
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
//        form.verify({
//            editor:function(value,item){
//                if(editor.txt.html() == '<p><br></p>'){
//                    return '请填写内容';
//                }
//            }
//        });
        form.on('submit(component-form-element)', function (data) {
//            data.field.lunbo_content = editor.txt.html();
//            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('bannerEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Banner/index')}")
                    } else {
//                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            if(data.value == 1){
                $("#banner_link").addClass('hidden');
                $("#banner_type").removeClass('hidden');
                if(banner_type == 1){
                    $("#assn_id").removeClass('hidden');
                }else if(banner_type == 2){
                    $("#information_id").removeClass('hidden');
                }else if(banner_type == 3){
                    $("#post_id").removeClass('hidden');
                }else if(banner_type == 4){
                    $("#video_id").removeClass('hidden');
                }else {
                    $("#answer_id").removeClass('hidden');
                }
            }else{
                $("#assn_id").addClass('hidden');
                $("#information_id").addClass('hidden');
                $("#post_id").addClass('hidden');
                $("#video_id").addClass('hidden');
                $("#answer_id").addClass('hidden');

                $("#banner_link").removeClass('hidden');
                $("#banner_type").addClass('hidden');
            }
        });
        form.on('select(role1)', function(data){
            banner_type = data.value;
            if(data.value == 1){
                $("#assn_id").removeClass('hidden');
                $("#information_id").addClass('hidden');
                $("#post_id").addClass('hidden');
                $("#video_id").addClass('hidden');
                $("#answer_id").addClass('hidden');
            }else if(data.value == 2){
                $("#assn_id").addClass('hidden');
                $("#information_id").removeClass('hidden');
                $("#post_id").addClass('hidden');
                $("#video_id").addClass('hidden');
                $("#answer_id").addClass('hidden');
            }else if(data.value == 3){
                $("#assn_id").addClass('hidden');
                $("#information_id").addClass('hidden');
                $("#post_id").removeClass('hidden');
                $("#video_id").addClass('hidden');
                $("#answer_id").addClass('hidden');
            }else if(data.value == 4){
                $("#assn_id").addClass('hidden');
                $("#information_id").addClass('hidden');
                $("#post_id").addClass('hidden');
                $("#video_id").removeClass('hidden');
                $("#answer_id").addClass('hidden');
            }else {
                $("#assn_id").addClass('hidden');
                $("#information_id").addClass('hidden');
                $("#post_id").addClass('hidden');
                $("#video_id").addClass('hidden');
                $("#answer_id").removeClass('hidden');
            }

        });
    });
</script>

</body>
</html>
